const { name } = require("./package");
const path = require("path");
module.exports = {
  publicPath: "./",
  runtimeCompiler: true,
  devServer: {
    headers: {
      "Access-Control-Allow-Origin": "*",
    },
    proxy: {
      "/selfApi": {
        target: "https://local.kuaijingai.com",
        changeOrigin: true,
        pathRewrite: {
          "^/selfApi": "",
        },
      },
    },
    disableHostCheck: true,
  },
  configureWebpack: {
    output: {
      library: `${name}-[name]`,
      libraryTarget: "umd", // 把微应用打包成 umd 库格式
      jsonpFunction: `webpackJsonp_${name}`,
    },
  },
  css: {
    loaderOptions: {
      less: {
        lessOptions: {
          javascriptEnabled: true,
        },
      },
    },
  },
  outputDir: "../../../../BE/apps/micro_apps/workApproval", // 打包目录
  productionSourceMap: false,
  chainWebpack: (config) => {
    // 多语言配置
    config.resolve.alias.set("vue-i18n", "vue-i18n/dist/vue-i18n.cjs.js");
    config.resolve.alias.set("moment", "dayjs");
    // less配置
    const oneOfsMap = config.module.rule("less").oneOfs.store;
    oneOfsMap.forEach((item) => {
      item
        .use("style-resources-loader")
        .loader("style-resources-loader")
        .options({
          patterns: [path.resolve(__dirname, "./src/common/styles/base.less")],
        })
        .end();
    });
    if (process.env.NODE_ENV === "production") {
      // 清除css，js版本号
      config.output.filename("js/[name].js?t=[hash]").end();
      config.output.chunkFilename("js/[name].js?t=[hash]").end();
      // 修改版本号配置
      config.plugin("extract-css").tap((args) => [
        {
          filename: "css/[name].css?t=[hash]",
          chunkFilename: "css/[name].css?t=[hash]",
        },
      ]);
    }
  },
};
